/****************************************************
* FUNCTION
*		rzCC
*
* DESCRIPTION
* 		retrieving-css-styles-via-javascript
*
* ARGUMENTS
*		s		  :	link ex: http://www.kapook.com .
*
****************************************************/
function rzCC(s)
{
   for(var exp=/-([a-z])/;
       exp.test(s);
       s=s.replace(exp,RegExp.$1.toUpperCase()));
   return s;
}

/****************************************************
* FUNCTION
*		_setStyle
*
* DESCRIPTION
* 		Set style for id
*
* ARGUMENTS
*		element		   	  :	 Dom element.
*		declaration		  :	 style value
*
****************************************************/
function _setStyle(element, declaration)
{
   	if (declaration.charAt(declaration.length-1)==';')
     	declaration = declaration.slice(0, -1);
   	var k, v;
    var splitted = declaration.split(';');
    for (var i=0, len=splitted.length; i<len; i++)
    {
     	k = rzCC(splitted[i].split(':')[0]);
      	v = splitted[i].split(':')[1];
      	eval("element.style."+k+"='"+v+"'");

   	}
 }

 /****************************************************
* FUNCTION
*		array_remove
*
* DESCRIPTION
* 		Remove element from array
*
* ARGUMENTS
*		array		   	  :	 instance of array.
*		from			  :	 start index
*		to				  :  end index
*
* EXAMPLE
*		array_remove(array, 0, 2); delete component from index 0 1 2
*		array_remove(array, 2);    delete component index 2
*
****************************************************/
function array_remove(array, from, to)
{
	  var rest = array.slice((to || from) + 1 || array.length);
	  array.length = from < 0 ? array.length + from : from;
	  return array.push.apply(array, rest);
}

/****************************************************
* FUNCTION
*		mouseX
*
* DESCRIPTION
* 		Find the absolute position of mouse X
*
* ARGUMENTS
*		ev			: 	event object of mouse event
*
* RETURN
*		pixel			: 	mouse X position
*
****************************************************/
function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
}

/****************************************************
* FUNCTION
*		mouseY
*
* DESCRIPTION
* 		Find the absolute position of mouse Y
*
* ARGUMENTS
*		ev			: 	event object of mouse event
*
* RETURN
*		pixel			: 	mouse Y position
*
****************************************************/
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}

/****************************************************
* FUNCTION
*		findPosX
*
* DESCRIPTION
* 		Find the absolute position of element X
*
* ARGUMENTS
*		element			: 	element Obj
*
* RETURN
*		pos_x			: 	postion X of element
*
****************************************************/
function findPosX(obj)
{
   	var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

/****************************************************
* FUNCTION
*		findPosY
*
* DESCRIPTION
* 		Find the absolute position of element Y
*
* ARGUMENTS
*		element			: 	element Obj
*
* RETURN
*		pos_y			: 	postion Y of element
*
****************************************************/
function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
 }

 /****************************************************
* FUNCTION
*		ExtractNumber
*
* DESCRIPTION
* 		Find the Extract Number
*
* ARGUMENTS
*		value			: 	the number
*
* RETURN
*		extract number	:	number
*
****************************************************/
function ExtractNumber(value) 
{ 
	var n = parseInt(value); return n == null || isNaN(n) ? 0 : n; 
} 
 

/****************************************************
* Object
*		BrowserDetect
*
* DESCRIPTION
* 		Detect Brower Version
*
****************************************************/
 var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
